package class_and_object.examination;

import java.util.Arrays;
import java.util.Date;
import java.util.Scanner;

/**
 * @author haomin
 * @date 2022/06/18 21:06
 **/
public class Test5_11 {
    public static void main(String[] args) {
        int count = 0;
        for (int i = 100; i <= 200 ; i++) {
            if((i % 6 == 0 || i % 5 == 0) && i % 30 != 0){
                System.out.print((++count) % 10 != 0 ? i + " " : i + "\n");
            }
        }
    }
}

class Test5_15 {
    public static void main(String[] args) {
        int count = 0;
        for (int i = '!'; i <= '~'; i++) {
            System.out.print((++count) % 10 == 0 ? (char)i + "\n" : (char)i + " ");
        }
    }
}

class Test5_24 {
    public static void main(String[] args) {
        double sum = 0;
        for (int i = 1; i <= 97; i+=2) {
            sum = 1.0*i/(i+2) + sum;
        }
        System.out.println(sum);
    }
}

class Test5_27 {
    public static void main(String[] args) {
        int count = 0;
        for (int i = 101; i < 2000; i++) {
            if(i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)){
                System.out.print((++count) % 10 == 0 ? i + "\n" : i + " ");
            }
        }
    }
}

class Test6_5 {
    public static void main(String[] args) {
        sort(3,2,1);
    }
    public static void sort(double num1,double num2,double num3){
        double[] data = {num1,num2,num3};
        Arrays.sort(data);
        for(double a : data){
            System.out.println(a);
        }
    }
}

class Test6_8 {
    public static void main(String[] args) {
        System.out.printf("%-8s%-8s%8s%8s\n","Celsius","Fahrenheit","Fahrenheit","Celsius");
        System.out.println("--------------------------------------------");
        for(double i = 40.0, j = 120.0 ; i >= 31.0 ; i--, j-=10){
            System.out.printf("%-8.1f%-8.1f%8.1f%8.2f\n",i,fahrenheitToCelsius(i),j,celsiusToFahrenheit(j));
        }
    }

    private static double celsiusToFahrenheit(double j) {
        return (5.0/9) * (j - 32);
    }

    private static double fahrenheitToCelsius(double i) {
        return (9.0/5) * i + 32;
    }
}

class Test6_20 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        countLetters(str);
    }

    private static void countLetters(String str) {
        int count = 0;
        for(int i = 0; i < str.length();i++){
            if(Character.isLetter(str.charAt(i))){
                count++;
            }
        }
        System.out.println(count);
    }
}

class Test7_7 {
    public static void main(String[] args) {
        int[] arr = new int[100];
        int[] counts = new int[10];
        for (int i = 0; i < 100; i++) {
            arr[i] = (int)(Math.random()*10);
            counts[arr[i]]++;
        }
        for(int i : counts){
            System.out.println(i);
        }
    }
}

class Test7_8 {
    public static void main(String[] args){
        System.out.println("请输入10个double类型的数：");
        Scanner in = new Scanner(System.in);
        double[] data = new double[10];
        int i = 0;
        while (i < 10){
            data[i] = in.nextDouble();
            i++;
        }

        System.out.println("平均值为" + average(data));
    }
    private static double average(double[] data){
        double sum = 0;
        for(double i : data){
            sum += i;
        }
        return sum/10;
    }
    private static int average(int[] data){
        int sum = 0;
        for(int i : data){
            sum += i;
        }
        return sum/10;
    }
}

class Test7_26{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入第一个数组长度和各值：");
        int[] arr1 = new int[in.nextInt()];
        for (int i = 0; i < arr1.length; i++) {
            arr1[i] = in.nextInt();
        }
        System.out.println("请输入第二个数组长度和各值：");
        int[] arr2 = new int[in.nextInt()];
        for (int i = 0; i < arr2.length; i++) {
            arr2[i] = in.nextInt();
        }

        System.out.println("两个数组相等情况：" + equals(arr1,arr2));
    }
    private static boolean equals(int[] arr1,int[] arr2){
        return Arrays.equals(arr1,arr2);
    }
}

class Test9_21 {
    static class StopWatch {
        private long starTime;
        private long endTime;

        public StopWatch() {
            Date date = new Date();
            starTime = date.getTime();
        }

        public long getStarTime(){
            return starTime;
        }
        public long getEndTime(){
            return endTime;
        }

        public void start(){
            Date date = new Date();
            starTime = date.getTime();
        }
        public void stop(){
            Date date = new Date();
            endTime = date.getTime();
        }

        public long getElapsedTime(){
            return endTime-starTime;
        }
    }

    public static void main(String[] args) {
        int[] arr = new int[100000];
        for(int i = 0 ; i < 100000;i++){
            arr[i] = (int)(Math.random()*100);
        }
        StopWatch stopWatch = new StopWatch();
        selectSort(arr);
        stopWatch.stop();
        System.out.println("执行时间：" + stopWatch.getElapsedTime());


//        int[] arr= {2,5,4,7,1,10,8,7,4};
//        selectSort(arr);
//        for(int i : arr){
//            System.out.println(i);
//        }
    }

    private static void selectSort(int[] arr){
        for(int i = 0;i < arr.length;i++){
            int maxValue = arr[0];
            int maxIndex = 0;
            for(int j = 0; j < arr.length-i;j++){
                if(arr[j] > maxValue){
                    maxValue = arr[j];
                    maxIndex = j;
                }
            }
            if(maxIndex != arr.length-i-1){
                arr[maxIndex] = arr[arr.length-i-1];
                arr[arr.length-i-1] = maxValue;
            }
        }
    }
}

class Test9_7 {
    static class Account {
        private int id;
        private double balance;
        private double annualInterestRate;
        private Date date = new Date();

        public Account() {
            id = 0;
            balance = 0.0;
            annualInterestRate = 0.0;
        }
        public Account(int id, double balance){
            this.id = id;
            this.balance = balance;
        }

        public int getId(){
            return id;
        }

        public double getBalance() {
            return balance;
        }

        public double getAnnualInterestRate() {
            return annualInterestRate;
        }

        public Date getDate() {
            return date;
        }

        public void setId(int id){
            this.id = id;
        }

        public void setBalance(double balance){
            this.balance = balance;
        }

        public void setAnnualInterestRate(double annualInterestRate){
            this.annualInterestRate = annualInterestRate;
        }

        public double getMonthlyInterestRate(){
            return getAnnualInterestRate()/12;
        }

        public double getMonthlyInterest(){
            return getMonthlyInterestRate() * getBalance();
        }

        public void withdraw(double money){
            this.balance += money;
        }

        public void deposit(double money){
            this.balance -= money;
        }
    }

    public static void main(String[] args) {
        Account account = new Account(1122,20000);
        account.setAnnualInterestRate(4.5/100);
        account.withdraw(2500);
        account.deposit(3000);
        System.out.println("余额：" + account.getBalance());
        System.out.println("月利率：" + account.getMonthlyInterestRate()*100 + "%");
        System.out.println("创建账户时间：" + account.getDate());
    }
}

class Test9_10 {
    static class QuadraticEquation {
        private double a;
        private double b;
        private double c;

        public QuadraticEquation(double a,double b,double c){
            this.a = a;
            this.b = b;
            this.c = c;
        }

        public double getA() {
            return a;
        }

        public double getB() {
            return b;
        }

        public double getC() {
            return c;
        }

        public double getDiscriminant(){
            return Math.pow(b,2) - 4 * a * c;
        }

        public double getRoot1(){
            return ((-b) + Math.sqrt(getDiscriminant())) / 2*a;
        }

        public double getRoot2(){
            return ((-b) - Math.sqrt(getDiscriminant())) / 2*a;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double a = in.nextDouble();
        double b = in.nextDouble();
        double c = in.nextDouble();
        QuadraticEquation qe = new QuadraticEquation(a,b,c);

        if(qe.getDiscriminant() > 0){
            System.out.println("root1:" + qe.getRoot1());
            System.out.println("root2:" + qe.getRoot2());
        }else if(qe.getDiscriminant() == 0){
            System.out.println("root1:" + qe.getRoot1());
        }else {
            System.out.println("The equation has no roots");
        }
    }
}

class Test10_9 {
    public static void main(String[] args) {
        int a = 1;
        String str = Integer.toString(a);
        int b = Integer.parseInt(str);

        double c = 2.0;
        String str2 = Double.toString(c);
        double d = Double.parseDouble(str2);

    }
}

class Test10_15 {
    public static void main(String[] args) {
        String str = "abc def";
        char[] data = str.toCharArray();
        for(char ret : data){
            System.out.println(ret);
        }
    }
}

class Test10_4 {
    static class MyPoint {
        private double x;
        private double y;

        public MyPoint(){
            this.x = 0.0;
            this.y = 0.0;
        }

        public MyPoint(double x,double y){
            this.x = x;
            this.y = y;
        }

        public double getX(){
            return x;
        }

        public double getY(){
            return y;
        }

        public double distance(MyPoint myPoint){
            return Math.sqrt(Math.pow((this.x- myPoint.x),2) + Math.pow((this.y-myPoint.y),2));
        }

        public double distance(double x,double y){
            return Math.sqrt(Math.pow((this.x-x),2) + Math.pow((this.y-y),2));
        }

        public static void main(String[] args) {
            MyPoint myPoint = new MyPoint();
            MyPoint myPoint1 = new MyPoint(2,2);
            System.out.println(myPoint.distance(myPoint1));
        }
    }
}

class Test11_1 {
    static class GeometricObject{
        private String color;
        private boolean isFilled;

        public GeometricObject(){
            this.color = "white";
            this.isFilled = false;
        }

        public GeometricObject(String color,boolean isFilled){
            this.color = color;
            this.isFilled = isFilled;
        }

        public String getColor() {
            return color;
        }

        public boolean isFilled() {
            return isFilled;
        }

        public void setColor(String color){
            this.color = color;
        }

        public void setFilled(boolean isFilled){
            this.isFilled = isFilled;
        }
    }

    static class Triangle extends GeometricObject{
        private double side1;
        private double side2;
        private double side3;

        public Triangle(){
            this.side1 = 1.0;
            this.side2 = 1.0;
            this.side3 = 1.0;
        }

        public Triangle(double side1,double side2,double side3,String color,boolean isFilled){
            super(color,isFilled);

            this.side1 = side1;
            this.side2 = side2;
            this.side3 = side3;
        }

        public double getSide1() {
            return side1;
        }

        public double getSide2() {
            return side2;
        }

        public double getSide3() {
            return side3;
        }

        public double getArea(){
            double s = getPerimeter()/2;
            return Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));
        }

        public double getPerimeter(){
            return side1+side2+side3;
        }

        public String toString() {
            return "Triangle: side1 = " + side1 + "Triangle: side2 = " + side2 + "Triangle: side3 = " + side3;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入三条边的成绩：");
        double side1 = in.nextDouble();
        double side2 = in.nextDouble();
        double side3 = in.nextDouble();
        System.out.println("请输入三角形颜色：");
        String color = in.next();
        System.out.println("请输入三角形是否填充：");
        boolean isFilled = in.nextBoolean();
        Triangle triangle = new Triangle(side1,side2,side3,color,isFilled);

        System.out.println("面积：" + triangle.getArea());
        System.out.println("周长：" + triangle.getPerimeter());
        System.out.println("color: " + triangle.getColor());
        System.out.println("isFilled: " + triangle.isFilled());
        System.out.println(triangle.toString());
    }
}

class Test13_6 {
    static class Circle {
        private double radius;

        public Circle(){
            radius = 1.0;
        }

        public Circle(double radius){
            this.radius = radius;
        }

        public double getArea(){
            return Math.PI*radius*radius;
        }
    }

    static class ComparableCircle extends Circle implements Comparable<ComparableCircle> {
        public ComparableCircle(){
            super();
        }

        public ComparableCircle(double radius){
            super(radius);
        }

        @Override
        public int compareTo(ComparableCircle o) {
            if(this.getArea() > o.getArea()){
                return 1;
            }else if(this.getArea() == o.getArea()){
                return 0;
            }else {
                return -1;
            }
        }
    }

    public static void main(String[] args) {
        ComparableCircle circle1 = new ComparableCircle(3);
        ComparableCircle circle2 = new ComparableCircle(5);

        if(circle1.compareTo(circle2) > 0){
            System.out.println("circle1 大");
        }else if(circle1.compareTo(circle2) == 0){
            System.out.println("一样大");
        }else {
            System.out.println("circle2 大");
        }
    }
}

class Test13_7 {
    static interface Colorable {
        public void howToColor();
    }

    static class GeometricObject {
        private String color;
        private boolean isFilled;

        public String getColor() {
            return color;
        }

        public boolean isFilled() {
            return isFilled;
        }

        public GeometricObject(){
            this.color = "white";
            this.isFilled = false;
        }

        public GeometricObject(String color,boolean isFilled){
            this.color = color;
            this.isFilled = isFilled;
        }

        @Override
        public String toString(){
            return "color: " + color + "isFilled: " + isFilled;
        }
    }

    static class Square extends GeometricObject implements Colorable{
        private double width;
        private double height;

        public Square(){
            super();
            this.width = 1.0;
            this.height = 1.0;
        }

        public Square(double width,double height,String color,boolean isFilled){
            super(color,isFilled);
            this.width = width;
            this.height = height;
        }

        public double getArea(){
            return this.width * this.height;
        }

        public double getPerimeter(){
            return 2 * (this.width + this.height);
        }

        @Override
        public void howToColor() {
            System.out.println("四条边有色");
        }

        @Override
        public String toString(){
            if(super.isFilled()){
                howToColor();
            }
            return super.toString();
        }
    }

    public static void main(String[] args) {
        Square[] squares = new Square[5];
        squares[0] = new Square(6,2,"white",true);
        squares[1] = new Square(2,2,"white",true);
        squares[2] = new Square(3,2,"white",false);
        squares[3] = new Square(4,2,"white",true);
        squares[4] = new Square(5,2,"white",false);

        for (int i = 0; i < 5; i++) {
            System.out.println(squares[i].toString());
        }
    }
}


